package simulation;

import java.awt.Dimension;
import java.util.List;

import util.Vector;

public class InverseSquareForceWallRepulsion extends WallRepulsion{
		private double screenWidth;
		private double screenHeight;
	
	
	
	public InverseSquareForceWallRepulsion(double magnitude, int dir, Dimension bounds){
		super(magnitude, dir);
		screenWidth = bounds.getWidth();
		screenHeight = bounds.getHeight();
	}
	
	
	@Override
	public void apply(List<Mass> myMasses) {
		if (!isOn()) 
			return;
		for(Mass m : myMasses){
			double distance = getDistance(m);
			double magnitude = getMagnitude(distance);
			Vector force = new Vector(getDirection(), magnitude);
			m.applyForce(force);
		}
		
	}

	
	private double getMagnitude(double distance) {
		double coeff = super.getMagnitude();
		double magnitude = coeff*(1/(distance*distance));
		return magnitude;
	}
	
	/*
	 * note the design decision in the README!
	 * 
	 */
	
	
	public double getDistance(Mass m){
		double distance = 0;
		if(getDirection() == DOWN_DIRECTION){
			distance = m.getY();
		}
		else if(getDirection() == LEFT_DIRECTION){
			distance = screenWidth - m.getX();
		}
		else if(getDirection() == UP_DIRECTION){
			distance = screenHeight - m.getY();
		}
		else if(getDirection() == RIGHT_DIRECTION){
			distance = m.getY();
		}
		return distance;
	}
}
